<include file="public/header" />
<include file="public/left" />
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="javascript:history.back();" title="返回列表">返回上一页</a>
            <div class="subject">
                <h3>系统设置</h3>
                <h5>网站系统权限资源管理</h5>
            </div>
        </div>
    </div>
    <form method="post" enctype="multipart/form-data" id="brandForm">
        <section>
            <ul class="ulColumn2">
                <li>
                    <span class="item_name" style="width:100px;">店铺：</span>
                    <eq name="data.status" value="2" >
                        <span class="item-title"/>申请修改还没通过</span>
                    </eq>
                    <eq name="data.status" value="1" >
                        <eq name="data.isopen" value="0" >
                            <input type="button" class="link_btn open" value="开店"  data-tip="确定开店吗?" data-url="{:url('Merchant/open',['shop_id'=>$shop_id])}"/>
                        </eq>
                        <eq name="data.isopen" value="1" >
                            <input type="button" class="link_btn open" value="关店"  data-tip="确定关店吗?" data-url="{:url('Merchant/open',['shop_id'=>$shop_id])}"/>
                        </eq>
                    </eq>
                </li>
                <li>
                    <span class="item_name" style="width:100px;">店铺简介：</span>
                    <input type="text" name="des" id="des" value="{$data.des}" style="width: 500px">    <input type="button" class="link_btn des" value="修改"  data-url="{:url('Merchant/des',['shop_id'=>$shop_id])}"/>
                </li>
                <li>
                    <span class="item_name" style="width:100px;">开启预约：</span>
                    <eq name="data.isbook" value="0" >
                        <input type="button" class="link_btn book" value="开启预约"  data-tip="确定开启预约吗?" data-url="{:url('Merchant/book',['shop_id'=>$shop_id])}"/>
                    </eq>
                    <eq name="data.isbook" value="1" >
                        <input type="button" class="link_btn book" value="关闭预约"  data-tip="确定开闭预约吗?" data-url="{:url('Merchant/book',['shop_id'=>$shop_id])}"/>
                    </eq>
                </li>
                <li>
                    <span class="item_name" style="width:100px;">是否配送：</span>
                    <eq name="data.issend" value="0" >
                        <input type="text" id="fee" value="{$data.send_fee}" placeholder="配送费"/>
                        <input type="button" class="link_btn send" value="开启配送" data-status="1"  data-tip="确定开启配送吗?" data-url="{:url('Merchant/send',['shop_id'=>$shop_id])}"/>
                    </eq>
                    <eq name="data.issend" value="1" >
                        <input type="button" class="link_btn send" value="关闭配送" data-status="0"   data-tip="确定开闭配送吗?" data-url="{:url('Merchant/send',['shop_id'=>$shop_id])}"/>
                        配送费：<input type="text" id="fee" readonly value="{$data.send_fee}"/>
                    </eq>
                </li>
                <li id="param-items">
                    <span class="item_name" style="width:100px;">营业时间：</span>   <input type="button" class="link_btn opentime" onclick="addOpenTime()" value="增加"/>
                    <input type="button" class="link_btn otsub" value="确定"/>
                    <volist name="data.open_time" id="ot">
                        <div style="margin-left: 100px;line-height: 40px" >
                            <a href="javascript:;" class="fa fa-move" title="拖动调整此显示顺序">移动</a>&nbsp;
                            <a href="javascript:;" onclick="deleteParam1(this)"  style="margin-top:10px;" title="删除">删除</a>
                            开始时间 <input name="starttime[]" type="text" style="width: 150px"  class="textbox textbox_295"  value="{$ot['starttime']}"/>
                            结束时间 <input name="endtime[]" type="text" style="width: 150px"   class="textbox textbox_295" value="{$ot['endtime']}"/>
                        </div>
                    </volist>
                </li>
                <li id="param-delivery">
                    <span class="item_name" style="width:100px;">配送时间：</span>   <input type="button" class="link_btn opentime" onclick="addDeliveryTime()" value="增加"/>
                    <input type="button" class="link_btn peisong_otsub" value="确定"/>
                    <volist name="data.delivery_time" id="ot">
                        <div style="margin-left: 100px;line-height: 40px" >
                            <a href="javascript:;" class="fa fa-move" title="拖动调整此显示顺序">移动</a>&nbsp;
                            <a href="javascript:;" onclick="deleteParam1(this)"  style="margin-top:10px;" title="删除">删除</a>
                            开始时间 <input name="de_starttime[]" type="text" style="width: 150px"  class="textbox textbox_295"  value="{$ot['starttime']}"/>
                            结束时间 <input name="de_endtime[]" type="text" style="width: 150px"   class="textbox textbox_295" value="{$ot['endtime']}"/>
                        </div>
                    </volist>
                </li>
                <li id="param-tell">
                    <span class="item_name" style="width:100px;">订餐电话：</span>   <input type="button" class="link_btn opentime" onclick="addTell()" value="增加"/>
                    <input type="button" class="link_btn tsub" value="确定"/>
                    <volist name="data.tell" id="t">
                        <div style="margin-left: 100px;line-height: 40px" >
                            <a href="javascript:;" class="fa fa-move" title="拖动调整此显示顺序">移动</a>&nbsp;
                            <a href="javascript:;" onclick="deleteParam1(this)"  style="margin-top:10px;" title="删除">删除</a>
                            <input name="tell[]" type="text" style="width: 150px"  class="textbox textbox_295"  value="{$t}"/>
                        </div>
                    </volist>
                </li>
                <li>
                    <span class="item_name" style="width:100px;">多少起送：</span>
                    <input type="text" id="full_distribution" value="{$data.full_distribution}" placeholder="配送费"/>
                    <input type="button" class="link_btn full_distribution" value="修改"  data-url="{:url('Merchant/full_distribution',['shop_id'=>$shop_id])}"/>
                </li>
            </ul>
        </section>
    </form>
</div>
</section>
</body>
</html>
<script type="text/javascript" src="__STATIC__/admin/js/jquery-ui-1.10.3.min.js"></script>
<script>
    $(function() {
        $("#param-items").sortable({handle: '.fa-move'});
        $("#param-delivery").sortable({handle: '.fa-move'});
        $("#param-tell").sortable({handle: '.fa-move'});
    })
    function addOpenTime() {
        $.ajax({
            "url": "{:url('Merchant/OpenTimeTpl')}",
            success: function(data) {
                $('#param-items').append(data);
            }
        });
        return;
    }
    function addDeliveryTime() {
        $.ajax({
            "url": "{:url('Merchant/DeliveryTimeTpl')}",
            success: function(data) {
                $('#param-delivery').append(data);
            }
        });
        return;
    }
    function addTell() {
        var tell=[];
        $("input[name='tell[]']").each(function(){
            tell.push($(this).val());
        });
        if(tell.length>=3){
            layer.alert('不能超过三个', {icon: 2}); return false;
        }
        $.ajax({
            "url": "{:url('Merchant/addTell')}",
            success: function(data) {
                $('#param-tell').append(data);
            }
        });
        return;
    }
    function deleteParam1(o) {
        $(o).parent().remove();

        return;

    }
</script>
<script>
    $(".tsub").click(function(){
        var tell=[];
        $("input[name='tell[]']").each(function(){
            tell.push($(this).val());
        });
        $.ajax({
            type: 'post',
            url: '{:url("Merchant/tell",['shop_id'=>$shop_id])}',
            data: {tell:tell},
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data == 1) {
                    //window.location.reload();
                    //$(obj).parents("tr").remove();
                    layer.closeAll();
                } else {
                    layer.alert(data, {icon: 2});  //alert('删除失败');
                }
            }
        })
    });
    $(".otsub").click(function(){
        var starttime=[];
        var endtime=[];
        $("input[name='starttime[]']").each(function(){
            starttime.push($(this).val());
        });
        $("input[name='endtime[]']").each(function(){
            endtime.push($(this).val());
        });
        console.log(starttime);
        if(starttime.length == 0){
            layer.alert('请填写营业时间', {icon: 2});  //alert('删除失败');
            return false;
        }
        $.ajax({
            type: 'post',
            url: '{:url("Merchant/setopentime",['shop_id'=>$shop_id])}',
            data: {starttime:starttime,endtime:endtime},
            dataType: 'json',
            success: function (data) {
                if (data == 1) {
                    //window.location.reload();
                    //$(obj).parents("tr").remove();
                    layer.closeAll();
                } else {
                    layer.alert(data, {icon: 2});  //alert('删除失败');
                }
            }
        })
    });
    $(".peisong_otsub").click(function(){
        var starttime=[];
        var endtime=[];
        $("input[name='de_starttime[]']").each(function(){
            starttime.push($(this).val());
        });
        $("input[name='de_endtime[]']").each(function(){
            endtime.push($(this).val());
        });
        console.log(starttime);
        if(starttime.length == 0){
            layer.alert('请填写营业时间', {icon: 2});  //alert('删除失败');
            return false;
        }
        $.ajax({
            type: 'post',
            url: '{:url("Merchant/setdeliverytime",['shop_id'=>$shop_id])}',
            data: {starttime:starttime,endtime:endtime},
            dataType: 'json',
            success: function (data) {
                if (data == 1) {
                    //window.location.reload();
                    //$(obj).parents("tr").remove();
                    layer.closeAll();
                } else {
                    layer.alert(data, {icon: 2});  //alert('删除失败');
                }
            }
        })
    });
    $(".open").click(function(){
        // 上下架
        var that=$(this);

        layer.confirm($(this).attr('data-tip'), {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: 'post',
                url: that.attr('data-url'),
                data: {id: that.attr('data-id')},
                dataType: 'json',
                success: function (data) {
                    if (data == 1) {
                        window.location.reload();
                        //$(obj).parents("tr").remove();
                        layer.closeAll();
                    } else {
                        layer.alert(data, {icon: 2});  //alert('删除失败');
                    }
                }
            })
        }, function () {
            layer.closeAll();
        });
    });
    $(".book").click(function(){
        var that=$(this);

        layer.confirm($(this).attr('data-tip'), {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: 'post',
                url: that.attr('data-url'),
                data: {id: that.attr('data-id')},
                dataType: 'json',
                success: function (data) {
                    if (data == 1) {
                        window.location.reload();
                        //$(obj).parents("tr").remove();
                        layer.closeAll();
                    } else {
                        layer.alert(data, {icon: 2});  //alert('删除失败');
                    }
                }
            })
        }, function () {
            layer.closeAll();
        });
    });
    $(".send").click(function(){
        var that=$(this);
        if($(this).data("status")==1 && $("#fee").val()==''){
            layer.alert('请填写配送费', {icon: 2});  //alert('删除失败');
            return false;
        }
        layer.confirm($(this).attr('data-tip'), {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: 'post',
                url: that.attr('data-url'),
                data: {fee: $("#fee").val()},
                dataType: 'json',
                success: function (data) {
                    if (data == 1) {
                        window.location.reload();
                        //$(obj).parents("tr").remove();
                        layer.closeAll();
                    } else {
                        layer.alert(data, {icon: 2});  //alert('删除失败');
                    }
                }
            })
        }, function () {
            layer.closeAll();
        });
    });
    $(".des").click(function(){
        $.ajax({
            type: 'post',
            url: $(this).attr('data-url'),
            data: {des: $("#des").val()},
            dataType: 'json',
            success: function (data) {
                if (data == 1) {
                    window.location.reload();
                    layer.closeAll();
                } else {
                    layer.alert(data, {icon: 2});  //alert('删除失败');
                }
            }
        })
    });
    $(".full_distribution").click(function(){
        $.ajax({
            type: 'post',
            url: $(this).attr('data-url'),
            data: {full_distribution: $("#full_distribution").val()},
            dataType: 'json',
            success: function (data) {
                if (data == 1) {
                    window.location.reload();
                    layer.closeAll();
                } else {
                    layer.alert(data, {icon: 2});  //alert('删除失败');
                }
            }
        })
    });

</script>